import type {
  UserAddDTOType,
  UserUpdateDTOType,
  UserSearchDTOType,
  LoginUserType,
} from '@/resources/interface/user/UserTypes'
import type { ResultTypes } from '@/resources/interface/ResultTypes'
import { HttpResultUtil } from '@/apis/utils/HttpResultUtil'

export class UserApi {
  private static addUrl: string = '/user/add'
  private static updateUrl: string = '/user/update'
  private static searchUrl: string = '/user/search'
  private static deleteUrl: string = '/user/delete'
  private static loginUrl: string = '/user/login'
  private static listUrl: string = '/user/list'

  static list() {
    return HttpResultUtil.awaitGet(this.listUrl, null, false)
  }

  static add(data: UserAddDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.addUrl, data, true)
  }

  static update(data: UserUpdateDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.updateUrl, data, true)
  }

  static search(data: UserSearchDTOType): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.searchUrl, data, false)
  }

  static delete(idList: Array<number>): Promise<ResultTypes> {
    return HttpResultUtil.awaitPost(this.deleteUrl, idList, true)
  }

  static login(data: LoginUserType) {
    return HttpResultUtil.awaitPost(this.loginUrl, data, false)
  }
}
